﻿// Copyright: 2012 
// Author: Minh Vu - YoungJ
// File name: Utilities.cs
// Solution: getlink
// Project: GetLink
// Time: 5:56 PM 03/05/2012

using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;

namespace GetLink
{
    public static class Utilites
    {
        public static string SizeToSize(this string size)
        {
            if (!size.Contains("MB")) return string.Empty;
            size = size.Replace("MB", string.Empty).Trim();
            return (Convert.ToDouble(size) * Math.Pow(1024, 2)).ToString(CultureInfo.InvariantCulture);
        }

        public static string FindLinkMediafire(this string text)
        {
            var url = text;
            var index = url.LastIndexOf("http://", StringComparison.Ordinal);
            if (index > -1)
            {
                url = url.Substring(index);
                index = url.LastIndexOf(" ", StringComparison.Ordinal);
                if (index > 0)
                    url = url.Substring(0, index);
            }
            return url;
        }

        public static void SendToIDM(this string uri)
        {
            try
            {
                Process.Start("C:\\Program Files\\Internet Download Manager\\IDMan.exe", " /n /d " + uri);
            }
            catch (Exception exception)
            {
                ShowMessageError(exception.Message + " IDM");
            }
        }

        public static void SendToQueue(this string uri)
        {
            try
            {
                Process.Start("C:\\Program Files\\Internet Download Manager\\IDMan.exe", " /a /d " + uri);
            }
            catch (Exception exception)
            {
                ShowMessageError(exception.Message + " IDM");
            }
        }

        public static void ShowMessage(string msg)
        {
            MessageBox.Show(msg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public static void ShowMessageError(string msg)
        {
            MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public static DialogResult ShowQuestionMessage(string msg)
        {
            return MessageBox.Show(msg, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);
        }
    }
}